﻿using System.Xml.Linq;
using QASPRibbon.Helpers;

namespace QASPRibbon.Controls
{
    /// <summary>
    /// Base class for all other SharePoint Ribbon definitions
    /// </summary>
    public abstract class RibbonElement
    {
        /// <summary>
        /// A string that identifies the control, such as "RibbonControl". No any dot at all.
        /// </summary>
        public string Id
        {
            get { return _id; }
            set { _id = value; }
        }

        internal string NameSpace
        {
            get { return _nameSpace; }
            set { _nameSpace = value; }
        }
        
        /// <summary>
        /// The text to label the control.
        /// </summary>
        public string Title
        {
            get { return _title.Localized(); }
            set { _title = value; }
        }
        
        /// <summary>
        /// A string that describes the button. 
        /// The description is displayed only when the button is in a menu 
        /// and is being rendered with the Menu32 display mode.
        /// </summary>
        public string Description
        {
            get { return _description.Localized(); }
            set { _description = value; }
        }

        /// <summary>
        /// An integer that specifies the order of placement among sibling XML nodes.
        /// </summary>
        public int Sequence { get; set; }

        /// <summary>
        /// Control' Identifier that used to register it in the Ribbon.
        /// </summary>
        public string FullId
        {
            get
            {
                return string.Format("{0}.{1}", NameSpace, Id);
            }
        }

        internal abstract string XmlTag { get; }
        
        internal abstract XElement AsXElement();

        protected RibbonElement()
        {

        }

        protected RibbonElement(string id)
            : this()
        {
            Id = id;
        }

        protected RibbonElement(string id, string title)
            : this(id)
        {
            Title = title;
        }

        #region Private fields

        private string _id = string.Empty;
        private string _nameSpace = string.Empty;
        private string _title = string.Empty;
        private string _description = string.Empty;

        #endregion
    }
}
